/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.deloitte.cvapp.dataaccess;

import ie.deloitte.cvapp.domain.Experience;
import ie.deloitte.cvapp.form.ExperienceBeanForm;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author damorales
 */
@Repository("experienceDAO")
@Transactional
public class ExperienceDAOImpl implements ExperienceDAO {

	@Autowired
	private SessionFactory sessionFactory;

	private Session currentSession() {
		return this.sessionFactory.getCurrentSession();
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void save(Experience e) {
		currentSession().saveOrUpdate(e);
	}

	public List<Experience> getById(String id) {
		Query namedQuery = currentSession()
				.getNamedQuery("Experience.findByIdEmployee");
		namedQuery.setParameter("employee_idEmployee", Integer.valueOf(id));
		List list = namedQuery.list();
		return list;
	}

//	public ExperienceBeanForm getExperienceBeanFormById(String id){
//		Experience experience = getById(id);
//		ExperienceBeanForm ebf = new ExperienceBeanForm();
//		
//		ebf.setCompanyname(experience.getCompanyname());
//		ebf.setPeriodStart(experience.getperiodStart());
//		ebf.setPeriodFinish(experience.getperiodFinish());
//		ebf.setRole(experience.getRole());
//		ebf.setDescription(experience.getDescription());
//		ebf.setResponsibilities(experience.getResponsibilities());
//		ebf.setprojectname(experience.getprojectname());
//		
//		return ebf;
//	}
	
	public void update(Experience e) {
		currentSession().update(e);
	}

	public List<Experience> getAll() {
		Query namedQuery = currentSession().getNamedQuery("Experience.findAll");
		List list = namedQuery.list();

		return list;
	}
}